<template>
  <div class="container">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="12" :offset="0"></el-col>
      <el-col :xs="24" :sm="12" :offset="0">
        <el-form label-width="80px" style="width: 70%" class="form">
          <h1 style="text-align: center">登录</h1>
          <hr />
          <el-form-item label="用户名">
            <el-input placholder="请输入用户名" v-model="userParams.username"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input
              placeholder="请输入密码"
              type="password"
              v-model="userParams.password"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="default" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup name="">
import request from '@/utils/request'
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const $router = useRouter()

let userParams = ref({
  username: '',
  password: ''
})

const login = async () => {
  let result = await request.post('/login', userParams.value)
  if (result.data.code == '0000') {
    localStorage.setItem('TOKEN', result.data.data)
    $router.push('/')
  }
}
</script>

<style scoped>
.container {
  width: 100%;
  height: 100vh;
  background: url('/backgroud.webp') no-repeat;
  background-size: cover;
}

.form {
  margin: 20vh auto;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>
